package com.czl.module_service.view

import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.SizeUtils
import com.czl.module_service.R
import com.lxj.xpopup.core.CenterPopupView

/**
 * @author by xubin
 * PS: Not easy to write code, please indicate.
 */
@SuppressLint("ViewConstructor")
class BaseCenterPopup(context: Context, val content: View, val title: String?) : CenterPopupView(context) {

    override fun onCreate() {
        super.onCreate()
        val ivClose = findViewById<ImageView>(R.id.base_pop_close_iv)
        ivClose.setOnClickListener { dismiss() }
        val frameLayout = findViewById<FrameLayout>(R.id.base_pop_content)
        frameLayout.addView(content)
        val titleTextView = findViewById<TextView>(R.id.base_pop_tv)
        if (title!=null && title.isNotEmpty()) {
            titleTextView.setText(title)
        } else {
            titleTextView.setText("提示")
        }
    }

    override fun getImplLayoutId(): Int {
        return R.layout.popup_base_center
    }

    override fun getMaxWidth(): Int {
        return ScreenUtils.getScreenWidth() - SizeUtils.dp2px(32f)
    }
}